package NC10_大数乘法;

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param s string字符串 第一个整数
     * @param t string字符串 第二个整数
     * @return string字符串
     */
    StringBuilder resultSb = new StringBuilder();
    public String solve (String s, String t) {
        // write code here

        int len2 = t.length() - 1;
        int lastZero = 0;
        while (len2 >= 0){
            int len1 = s.length() - 1;
            int carry = 0;

            int num1 = t.charAt(len2--) - '0';
            StringBuilder sb = new StringBuilder();
            while (len1 >= 0 || carry > 0){
                int num2 = len1 < 0 ? 0 :s.charAt(len1--) - '0';
                int num = num1 * num2 + carry;
                sb.insert(0, num % 10);
                carry = num / 10;


            }
            for (int i = 0; i < lastZero; i++){
                sb.append(0);
            }
            lastZero++;
            Add(sb);

        }
        return resultSb.toString();
    }

    private void Add(StringBuilder sb) {
        StringBuilder newSb = new StringBuilder();
        int len1 = sb.length() - 1;
        int len2 = resultSb.length() - 1;
        int carry = 0;
        while (len1 >= 0 || len2 >= 0 || carry > 0){
            int num1 = len1 < 0 ? 0 : sb.charAt(len1--) - '0';
            int num2 = len2 < 0 ? 0 : resultSb.charAt(len2--) - '0';

            int num = num1 + num2 + carry;
            newSb.insert(0, num % 10);
            carry = num / 10;
        }

        resultSb = newSb;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String sting = solution.solve("11", "99");
        System.out.println(sting);
    }
}